/*
 * @Author: Donald duck tang5722917@163.com
 * @Date: 2024-06-04 17:40:34
 * @LastEditors: Donald duck tang5722917@163.com
 * @LastEditTime: 2024-06-28 19:01:03
 * @FilePath: \mysticism-mud\lpc_atest\lpc_assert.c
 * @Description: 
 * Copyright (c) 2024 by Donald duck email: tang5722917@163.com, All Rights Reserved.
 */
#include "lpc_atest.h"

nosave mixed * assert_info;
nosave string test_func;
//相等字符串比较判定
void add_assert_info(mixed exp, mixed act,int result){assert_info += ({exp,act,result});}
void assert_info_init(){assert_info = ({});}
mixed * assert_info_end(){return copy(assert_info);}
void set_test_func(string test_fun){test_func = test_fun;}

void assert_equal_string(string exp,string act) {
    string * info = ({});
    info +=({test_func +":"+"String Assert"});
    if(strcmp(exp,act) == 0) {
        info +=({PASS});
        info +=({"Assert "+exp + " == " + act});
    }
    else  {
        info +=({FAIL});
        info +=({"Assert "+exp + " != " +act});
    }
    assert_info += copy(info);
}

//相等对象判定
void assert_equal_object(object exp,object act) {
    string * info = ({});
    string exp_file = file_name(exp);
    string act_file = file_name(act);
    info +=({test_func +":"+"Object Assert"});
    if(strcmp(exp_file,act_file) == 0) {
        info +=({PASS});
        info +=({"Assert "+exp_file + " == " + act_file});
    }
    else  {
        info +=({FAIL});
        info +=({"Assert "+exp_file + " != " +act_file});
    }
    assert_info += copy(info);
}

//相等INT判定
void assert_equal_INT(int exp,int act) {
    string * info = ({});
    info +=({test_func+":"+"INT Assert"});
    if(exp == act) {
        info +=({PASS});
        info +=({"Assert "+exp + " == " + act});
    }
    else  {
        info +=({FAIL});
        info +=({"Assert "+exp + " != " +act});
    }
    assert_info += copy(info);
}

//相等逻辑判定
void assert_equal_Logic(int exp,int act) {
    string * info = ({});
    info +=({test_func +":"+"Logic Assert"});
    if((exp && 1) == (act && 1)) {
        info +=({PASS});
        info +=({"Assert "+((exp && 1) ? "True" : "False") + " == " +((act && 1) ? "True" : "False")});
    }
    else  {
        info +=({FAIL});
        info +=({"Assert "+((exp && 1) ? "True" : "False") + " != " +((act && 1) ? "True" : "False")});
    }
    assert_info += copy(info);
}
